window.onload = function () {
    let RegTel = /^1[3|4|5|7|8]\d{9}$/;
    let RegQq = /^[1-9]\d{4,}/
    let RegName = /^[\u4e00-\u9fa5]{2,8}$/
    let RegMsg = /^\d{6}$/
    let RegPwd = /^[a-zA-Z0-9_-]{6,16}$/

    let tel = document.querySelector('#tel');
    let qq = document.querySelector('#qq');
    let name = document.querySelector('#name');
    let msg = document.querySelector('#msg')
    let pwd = document.querySelector('#pwd')
    let surePwd = document.querySelector('#surePwd')
    regexp(tel, RegTel);
    regexp(qq, RegQq);
    regexp(name, RegName)
    regexp(msg, RegMsg)
    regexp(pwd, RegPwd)

    function regexp(ele, reg) {
        ele.onblur = function () {
            if(reg.test(this.value)) {
                this.nextElementSibling.className = 'success';
                this.nextElementSibling.innerHTML = '<i class="success_icon"></i>输入正确'
            } else {
                this.nextElementSibling.className = 'erroe';
                this.nextElementSibling.innerHTML = '<i class="error_icon"></i>输入不正确，请从新输入'
            }
        }
    }
    surePwd.onblur = function () {
        if(this.value === pwd.value) {
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = '<i class="success_icon"></i>输入正确'
        } else {
            this.nextElementSibling.className = 'erroe';
            this.nextElementSibling.innerHTML = '<i class="error_icon"></i>两次密码输入不一致，请重新输入'
        }
    }
}
